# @Time: 2023/7/6 14:50
# @File: login_main.py
import sys

from PyQt5.QtCore import QCoreApplication



from methods.login import VerifyImage
from methods.login.login import Ui_login_MainWindow
from interface import *
from app import *


class login_window(QMainWindow, Ui_login_MainWindow):
    def __init__(self):
        super(login_window, self).__init__()
        self.setupUi(self)  # 创建窗体对象
        self.init()
        # 定义验证码
        # self.code=VerifyImage.get_verify_code()
        self.admin = "123"
        self.Password = "000"
        self.pushButton_2.clicked.connect(self.login_button)  # 为退出按钮绑定槽函数
        self.show()


    def init(self):
        self.pushButton.clicked.connect(self.login_button)  # 连接槽
        self.pushButton_3.clicked.connect(self.login_button_3)  # 连接槽


    def login_button_3(self):

        self.code=VerifyImage.get_verify_code()
        self.pushButton_3.setText(f"{self.code}")

    def login_button(self):
        if self.lineEdit_2.text() == "":
            QMessageBox.warning(self, '警告', '密码不能为空，请输入！')

        elif self.VertifyCode.text() != self.code:
            print(f"{self.VertifyCode.text()}")
            print(f"{self.code}")
            # 关联“错误框”按钮的方法
            QMessageBox.critical(None, '错误', '验证码错误，请改正！', QMessageBox.Ok)

            return None

        # if  self.password == self.lineEdit.text():
        if (self.lineEdit_2.text() == self.Password) and self.lineEdit.text() == self.admin:
            app = App()
            self.close()
            app.run(True)
        else:
            QMessageBox.critical(self, '错误', '密码错误！')
            self.lineEdit_2.clear()
            return None
if __name__ == '__main__':
    from PyQt5 import QtCore
    QtCore.QCoreApplication.setAttribute(QtCore.Qt.AA_EnableHighDpiScaling)  # 自适应分辨率
    app = QApplication(sys.argv)
    window = login_window()
    # 显示登陆窗口
    window.show()
    sys.exit(app.exec_())


